package com.lavegue.common;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * author: luoweibin
 * date:2012-2-28
 * description:
 *
 */
public final class SystemConfig {

private static final Map<String, String> map = new HashMap<String, String>();
	
	private static final String[] CONFIG_FILES = {"/config.properties"};
	//配置文件的字符编码
	private static final String FILE_CHARTSET = "UTF-8";
	
	//应用的class文件所在的路径
	public static final String PROJECT_CLASS_PATH = SystemConfig.class.getResource("/").getPath(); 
	
	static {
		init();
	}
	
	
	private static synchronized void init() {
			for (String  file : CONFIG_FILES) {
				Properties pt = new Properties();
				InputStream reader = null;
				try {
					
					reader = SystemConfig.class.getResourceAsStream(file);
						// new InputStreamReader(SystemConfig.class.getResourceAsStream(file), FILE_CHARTSET);
					pt.load(reader);
					Set keySet = pt.keySet();
					for (Object key : keySet) {
						map.put(key.toString(), pt.get(key).toString());
					}
				} catch (Exception e) {
					e.printStackTrace();
				}  finally {
					if (reader != null) {
						try {
							reader.close();
						} catch (IOException e) {
							e.printStackTrace();
						}
					}
				}
			}
	}
	
	public static String getValue(String key) {
		return map.get(key);
	}
	
	public static int getIntValue(String key) {
		return Integer.valueOf(getValue(key));
	}
	
	public static int getPrice30() {
		return getIntValue("price_30");
	}
	
	public static int getPrice60() {
		return getIntValue("price_60");
	}
	
	public static int getPrice90() {
		return getIntValue("price_90");
	}
	
	public static int getPrice200() {
		return getIntValue("price_200");
	}
	
	public static int getPrice500() {
		return getIntValue("price_500");
	}
	
	public static int getPrice3() {
		return getIntValue("price_3");
	}
	
	/**
	 * 商家的商户号,有腾讯公司唯一分配
	 * @return
	 */
	public static String getbargainorId() {
		return getValue("bargainor_id");
	}
	
	/**
	 * 密钥
	 * @return
	 */
	public static String getSecretKey() {
		return getValue("secret_key");
	}
	
	/**
	 * 财付通支付后的处理url
	 * @return
	 */
	public static String getReturnUrl() {
		return getValue("return_url");
	}
	
	
	public static void main(String[] args) {
		System.out.println(SystemConfig.getPrice3());
		System.out.println(SystemConfig.getPrice30());
		System.out.println(SystemConfig.getPrice60());
		System.out.println(SystemConfig.getPrice90());
		System.out.println(SystemConfig.getPrice200());
		System.out.println(SystemConfig.getPrice500());
		System.out.println(SystemConfig.getbargainorId());
		System.out.println(SystemConfig.getSecretKey());
		System.out.println(SystemConfig.getReturnUrl());
	}
}


